<!-- jsp to load image form server -->

<%@ page import="java.util.*, java.sql.*, java.io.*, java.sql.*" %>

<%
String sql = "";
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

out.clear();
out=pageContext.pushBody(); 

OutputStream output = response.getOutputStream();
InputStream input = null; 

String parameter = request.getParameter("parameter");

System.out.println(parameter);

try {
	
	 Class.forName("com.mysql.jdbc.Driver");
	 String jdbcUrl="jdbc:mysql://147.47.228.6:3306/jsptest"; // my ip : 147.47.228.6
	 String id="user1";
	 String pass="1234";
	 
	 con=DriverManager.getConnection(jdbcUrl,id,pass);
	 //out.println("Connection Success");
	 
	 Statement stmt = con.createStatement();
	  
    
    sql =" select thumb from blob_test where img_no = 5 ";
    //pstmt = con.prepareStatement(sql);
    
    rs = stmt.executeQuery(sql);
    
    if (rs.next()) {
    	System.out.println("asdf");
        input = rs.getBinaryStream("thumb");
        int byteRead;
        while((byteRead = input.read()) != -1) {
        output.write(byteRead);
        }
        input.close();
    }
} catch(Exception e) {
    out.print(e);
} finally {
    try {if (rs != null) rs.close();} catch (Exception ex) {}
    try {if (pstmt != null) pstmt.close();} catch (Exception ex) {}
    try {if (con != null) con.close();} catch (Exception ex) {}
}

input.close();
output.flush();
output.close();
%>
